local thbattle__bayunzi_shenyin = fk.CreateSkill {

  name = "thbattle__bayunzi_shenyin",

  tags = { Skill.Compulsory, },

}



thbattle__bayunzi_shenyin:addEffect("active", {
  name = "thbattle__bayunzi_shenyin",
  prompt = "#thbattle__bayunzi_shenyin",
  anim_type = "control",
  target_num = 1,
  target_filter =function (self, player, to_select, selected, selected_cards)
    return #selected < 1 and #to_select:getCardIds("hej") > 0
  end,
  max_phase_use_time = 2,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local card = room:askForCardChosen(player, target, "hej", thbattle__bayunzi_shenyin.name, "#thbattle__bayunzi_shenyin-choose_card")
    target:addToPile("thbattle__bayunzi_shenyin", card, false, thbattle__bayunzi_shenyin.name, player, { player.id, target.id })
  end,
})

thbattle__bayunzi_shenyin:addEffect(fk.EventPhaseEnd, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(thbattle__bayunzi_shenyin.name) and player.phase == Player.Finish
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      if #p:getPile("thbattle__bayunzi_shenyin") > 0 then
        room:moveCardTo(p:getPile("thbattle__bayunzi_shenyin"), Card.PlayerHand, p, fk.ReasonJustMove,
          "thbattle__bayunzi_shenyin")
      end
    end
  end
})

return thbattle__bayunzi_shenyin